var varCurrent=0;
var _tabMax=0; //Valor maximo q toma el tab

function openTabs(title, pagina){
	var inicio = document.getElementById('tab.0');
	inicio.className="tab0";
	var tabCurrent = document.getElementById("tab."+varCurrent);
	var divCurrent = document.getElementById("div."+varCurrent);
	var divTabs = document.getElementById("tabs");
	var divContent = document.getElementById("divContent");
	var span = document.createElement("span");
	var div = document.createElement("div");
	
	div.className='divBody';
	//div.innerHTML="Esto es nuevo<br>asdsadasdsa sad sad asd as<br>qwewq";
	//span.id="tab."+varCurrent+1;
	//span.className="_tabMax";
	tabCurrent.className="tab0";
	divCurrent.style.visibility ='hidden';
	document.getElementById('divLog').innerHTML=_tabMax;
	_tabMax = parseInt(_tabMax)+1;
	varCurrent = _tabMax;
	div.id="div."+(_tabMax);
	span.innerHTML="<span id='tab."+(_tabMax)+"' class='tabCurrent' onclick='changeTabs(this)'>"+title+"<img src='IMAGES/cancel.gif' class='tabImg' onclick='closeTabs(this)'></img>";
	//span.innerHTML=title+"<img src='images/cancel.gif' class='tabImg' onclick='closeTabs(this)'></img>";
	//alert (span.innerHTML);
	divContent.appendChild(div);
	divTabs.appendChild(span);
	return div;	
}
//Intercambiar entre las pesta�as
function changeTabs(Object){
	var ide=Object.id
	var divId =  ide.split('.');
	//if (varCurrent == divId[1]) return;
	if (!document.getElementById("tab."+varCurrent)) {
		while (true){
			varCurrent--;
			var fDiv = document.getElementById('tab.'+varCurrent);
			if (fDiv) break;
		}
		changeTabs(fDiv);
		//var fDiv = document.getElementById('tab.0');
		//if (fDiv) changeTabs(fDiv);
		//alert ("Eliminando");
		return;
	}
	
	//alert (divId);
	if (!document.getElementById('tab.'+divId[1])) return;
	document.getElementById("tab."+varCurrent).className="tab0";
	document.getElementById("div."+varCurrent).style.visibility ='hidden';
	//alert ("div."+varCurrent);
	if (document.getElementById('tab.'+divId[1]))
		document.getElementById('div.'+divId[1]).style.visibility ='visible';
	Object.className="tabCurrent";
	varCurrent=divId[1];
	//alert ("change");
}

function clearTabs(){
	tabs = $$('tabs');
	var tabs = tabs.getElementsByTagName("span");
	for (var i=1;i<tabs.length;i++){
		if (tabs[i].className=="tab0" || tabs[i].className=="tabCurrent"){
			closeTabs(tabs[i],'0');
		}
	}
	varCurrent = 0;
	
}

function closeTabs(Object, type){
	//alert (Object.parentNode.id);
	/*if (Object.parentNode.id!="tabs")	var fSpan = Object.parentNode;
	else								var fSpan = Object;
	*/
	if (type==null)		var fSpan = Object.parentNode;
	else				var fSpan = Object;
	var ide=fSpan.id
	if (ide == "tab.0") {return;};
	var divId =  ide.split('.');
	var fDiv = fSpan.parentNode;
	fDiv.removeChild(fSpan);
	var divC = document.getElementById('div.'+divId[1]);
	//alert (divId[1]);
	divC.parentNode.removeChild(divC);
	//alert ("asdas");
	//fDiv = divC.parentNode;
}